package com.ihd.ihardware.view.tzc.me.viewmodel;

import android.app.Application;
import android.arch.lifecycle.AndroidViewModel;
import android.support.annotation.NonNull;

import com.ihd.ihardware.view.tzc.me.model.MemberRepository;

import java.io.File;

public class AddMemberViewModel extends AndroidViewModel {

    private MemberRepository mMemberRepository;

    public AddMemberViewModel(@NonNull Application application) {
        super(application);
    }

    public void updateHead(File f) {
        if (mMemberRepository == null)
            mMemberRepository = new MemberRepository();
        mMemberRepository.updateHead(f);
    }

    public void AddMember(String avatar, int relation, int sex, String birthday, String height, String weight) {
        if (mMemberRepository == null)
            mMemberRepository = new MemberRepository();
        mMemberRepository.addMember(avatar, relation, sex, birthday, height, weight);
    }

    public void editMember(String avatar, int relation, int sex, String birthday, String height, String weight, String memberId) {
        if (mMemberRepository == null)
            mMemberRepository = new MemberRepository();
        mMemberRepository.editMember(avatar, relation, sex, birthday, height, weight, memberId);
    }

    public void handWeighing(String familyId, String weight) {
        if (mMemberRepository == null)
            mMemberRepository = new MemberRepository();
        mMemberRepository.handWeighing(familyId, weight);
    }

    @Override
    protected void onCleared() {
        super.onCleared();
        if (null != mMemberRepository) {
            mMemberRepository.onDestroy();
            mMemberRepository = null;
        }
    }
}
